<template>
	<view>
		<cu-custom v-if="customShow" bgColor="bg-fafafa" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">系统设置</block>
		</cu-custom>
		<view class="cu-list menu margin-top-sm">
			<view class="cu-item arrow">
				<button class="cu-btn content" open-type="feedback">
					<text class="text-baseColor">意见反馈</text>
				</button>
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="cu-item" @click="clearCache">
				<view class="content">
					<text class="text-baseColor">清除缓存</text>
				</view>
				<view class="action">
					<text class="text-grey text-sm">{{cacheSize}}</text>
				</view>
			</view>
			<!-- #endif -->
			<view class="cu-item arrow" @click="$util.toPage" :data-url='"../../pages/article/detail?article_id="+appConfig.about_us_article'>
				<view class="content">
					<text class="text-baseColor">关于我们</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="text-baseColor">当前版本</text>
				</view>
				<view class="action">
					<text class="text-grey text-sm">{{versionCode}}</text>
				</view>
			</view>

		</view>
		<view class="flex flex-direction">
			<button class="cu-btn bg-white margin-top-xl lg text-red text-bold" @click="loginOut" style="font-size: 26upx;height: 100upx;">退出登录</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	let me = null;
	export default {
		data() {
			return {
				customShow: 0,
				versionCode: '',
				cacheSize: ''
			};
		},
		onLoad() {
			me = this;
			//#ifdef H5 || MP-BAIDU || MP-TOUTIAO || MP-WEIXIN
			this.customShow = 1;
			//#endif
			me.versionCode = this.systemInfo.appVersion;
		},
		onReady() {
			// #ifdef APP-PLUS
			plus.io.resolveLocalFileSystemURL("_doc/", function(entry) {
				entry.getMetadata(function(metadata) {
					me.cacheSize = (metadata.size / 1048576).toFixed(2) + " MB";
				}, function() {
					console.log("缓存目录大小计算失败");
				}, true);
			});
			// #endif

		},
		computed: {
			...mapState({
				appConfig: ({
					baseModule
				}) => baseModule.appConfig,
				navHeight: ({
					baseModule
				}) => baseModule.navHeight,
				referrerId: ({
					baseModule
				}) => baseModule.referrerId
			})
		},
		methods: {
			...mapMutations(['userModule/logout']),
			loginOut() {
				this.setUserInfo(null);
				this['userModule/logout']();
				me.setStore('navHeight', me.navHeight);
				me.setStore("referrerId", me.referrerId);
				uni.navigateBack();
			},
			clearCache() {
				plus.nativeUI.showWaiting();
				setTimeout(function() {
					plus.io.resolveLocalFileSystemURL("_doc", function(entry) {
						entry.removeRecursively(function(entry) {
							plus.nativeUI.closeWaiting();
							console.log("缓存清理成功");
							//plus.storage.clear();
							plus.io.resolveLocalFileSystemURL("_doc/", function(entry) {
								entry.getMetadata(function(metadata) {
									me.cacheSize = parseFloat(metadata.size / 1048576).toFixed(2) + " MB";
								}, function() {
									plus.nativeUI.closeWaiting();
									console.log("缓存目录大小计算失败");
								}, true);
							});
						}, function(e) {
							plus.nativeUI.closeWaiting();
							console.log("缓存清理失败");
						});
					}, function(e) {
						plus.nativeUI.closeWaiting();
						console.log("缓存清理失败");
					});
				}, 1000);
			}
		}
	}
</script>

<style>
	button {
		border-radius: 0;
	}
</style>
